﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BostonAzureSite.ViewHelpers
{
    public static class SemanticMarkupHelpers
    {
        // TODO: mapping from UTC to Local could be problematic in the future if the local time becomes variable (user-dependent)

        internal static readonly string DestinationTimeZone = "Eastern Standard Time";

        internal static TimeZoneInfo GetLocalTimeZone()
        {
            // TODO: fix this - id/string should come from config or resource
            // TODO: document this - to see your local Time Zone Id, run this with PowerShell from your local machine: [System.TimeZoneInfo]::Local.Id
            return TimeZoneInfo.FindSystemTimeZoneById(DestinationTimeZone);
        }

        /// <summary>
        /// Returns semantic HTML markup showing LOCAL TIME for provided date/time. 
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="dateTimeUtc">Expecting date/time as UTC</param>
        /// <returns>formatted string (<div title="utc">Tue Jan 12, 2010 @ 7:00 PM</div>), or empty if input is null</returns>
        public static MvcHtmlString GetLocalDateTimeSemanticMarkup(this HtmlHelper helper, DateTime? dateTimeUtc)
        {
            if (!dateTimeUtc.HasValue) return new MvcHtmlString("");

            ISemanticMarkupBuilder semanticMarkupBuilder = new MicroformatMarkupBuilder(); // TODO: Use Dependency Injection
            string semanticMarkup = semanticMarkupBuilder.GetSemanticMarkupForTimeZone(dateTimeUtc.Value, GetLocalTimeZone());
            return new MvcHtmlString(semanticMarkup);
        }
    }
}
